package perf.form;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import perf.data.Binary;
import perf.data.Run;
import perf.store.StoreManager;

public class RunBean {

	private String selected;
	
	public void setRuns( List<SelectItem> list ) {
		System.out.println( "setRuns: " + list.size() );
		for ( SelectItem s : list ) {
			System.out.println( s );
		}
		//this one gets called with 0 elements in the list
		//everytime an object is selected.
	}
	
	public List<SelectItem> getRuns( ) {
		ArrayList<SelectItem> runs = new ArrayList<SelectItem>();
		
		List<Run> runlist = StoreManager.store().list().runs();

		runs.add( 0, new SelectItem( "" ) );
		for (int i = 0; i < runlist.size(); i++ ) {
			runs.add( i+1, new SelectItem( runlist.get( i ).getName() ) );
		}
		
		return runs;
	}
	
	public void setBins( List<SelectItem> items) {
		
		
	}
	
	public List<SelectItem> getBins() {
		ArrayList<SelectItem> list = new ArrayList<SelectItem>();
		
		if ( selected != null ) {
			List<Binary> bins = StoreManager.store().list().bins( selected );
			for (Binary b : bins) {
				list.add( new SelectItem( b.getName() ) );
			}
		}
		return list;
	}
	
	public void setSelectedRun( String selected ) {
		this.selected = selected;
	}
	
	public String getSelectedRun( ) {
		return selected;
	}
}
